const fs = require('fs');
const path = require('path');

const jsonDir = path.join(__dirname, 'output', 'json');

fs.readdirSync(jsonDir).forEach(file => {
  if (file.endsWith('.json')) {
    const filePath = path.join(jsonDir, file);
    const rawContent = fs.readFileSync(filePath, 'utf-8');
    try {
      const obj = JSON.parse(rawContent);
      const minified = JSON.stringify(obj);
      fs.writeFileSync(filePath, minified, 'utf-8');
      console.log(`已压缩: ${file}`);
    } catch (e) {
      console.error(`压缩失败: ${file}，错误: ${e}`);
    }
  }
});

console.log('✅ JSON 文件已全部压缩完成');
